package com.hqbzl.chat.utils;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class BufferUtils {
    public static void log(ByteBuf buf) {
        StringBuilder builder = new StringBuilder();
        final int capacity = buf.capacity();
        final int readerIndex = buf.readerIndex();
        final int writerIndex = buf.writerIndex();
        builder.append("\n+--------+-------------------------------------------------+----------------+\n");
        builder.append("\tcapacity: ").append(capacity).append("\t");
        builder.append("readerIndex: ").append(readerIndex).append("\t");
        builder.append("writerIndex: ").append(writerIndex);
        builder.append("\n+--------+-------------------------------------------------+----------------+\n");
         ByteBufUtil.appendPrettyHexDump(builder, buf);
        log.debug("{}", builder);
    }

    public static void main(String[] args) {
        final ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
        buffer.writeInt(1);
        log(buffer);
    }
}
